/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class MyBlockingQueue {
    private int[] array =null;
    private int size =0;
    private int start =0;
    private int end =0;
    public MyBlockingQueue(int n) {
        array =new int[n];
    }

    public void put(int value) throws InterruptedException {
     synchronized (this){
         while (size >= array.length){
             //阻塞
             this.wait();
         }
         array[end++] =value;
         if (end>=array.length){
             end=0;
         }
         size++;
         this.notify();
     }
    }
    public int take() throws InterruptedException {
       synchronized (this){
           while (size==0){
               //阻塞
               this.wait();
           }
           int ret =array[start++];
           size--;
           if(start>=array.length){
               start=0;
           }
           this.notify();
           return ret;
       }
    }
}
